package com.aaron.activity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.ValueCallback;
import com.aaron.cdc.R;
import com.aaron.customer.CwebView;
import com.aaron.util.js.InJavaScriptLocalObj;

public class WebViewActivity extends BaseActivity {
	private CwebView cwebView;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		cwebView = (CwebView) findViewById(R.id.wv);
		cwebView.client();
		cwebView.addJavascriptInterface(new InJavaScriptLocalObj(), "local_obj");
		cwebView.loadUrl("file:///android_asset/index.html");
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();

	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			new Handler().postDelayed(new Runnable() {
				@SuppressLint("NewApi")
				public void run() {
					cwebView.evaluateJavascript("click1()",
							new ValueCallback<String>() {

								@Override
								public void onReceiveValue(String value) {
									// TODO Auto-generated method stub
								}
							});
				}
			}, 3000);
			return true;
		}
		return false;
	}
}
